<?php
use common\helper\StringHelper;

$this->context->bodyClass="page-cart";
?>

<?php $this->beginBlock('css');?>
  <link rel="stylesheet" type="text/css" href="<?= Yii::getAlias('@static')?>/wap/liketry/css/cart.css">
<?php $this->endBlock();?>

<header>
  <div class="header-left" id="back"><span class="icon icon-arrow-left"></span></div>
  <h1>购物车</h1>
  <div class="header-right" onclick="$.go('<?=Yii::$app->urlManager->createUrl(['index'])?>');" ><span class="icon icon-home"></span></div>
</header>
<section class="cart-empty" <?php if(!empty($data)){echo 'style="display:none"';}?> id="cartEmpty">
  <div class="cart-empty-image icon-cart-order"></div>
  <div class="cart-empty-tips">您的购物车空空如也<br>赶紧来挑几件干货吧</div>
  <div class="cart-empty-btn"><a href="<?=Yii::$app->urlManager->createUrl(['index']);?>">去首页逛逛</a></div>
</section>
<?php if(!empty($data)):?>
<section class="cart-list" id="cartListWrap">
	<div class="shop-discount"><?php if(!empty($fullcut)):?><span>满减</span><i id="fullcut"><?=$fullcut;?></i><?php endif;?></div>
  <ul id="cartList">
    <?php
    foreach ($data as $key=>$item):?>
    <li class="<?php if(!$item['status']){ echo 'disabled';}?> box-sizing box" data-cart-id="<?=$item['cart_id'];?>" data-product-id="<?=$item['product_id'];?>">
		<div class="cart-select"><span class="radio"></span></div>
      <div class="cart-image"><a href="<?=Yii::$app->urlManager->createUrl(['goods-detail/index','product_id'=>$item['product_id']]);?>"><img src="<?=$item['pic'];?>"></a></div>
      <div class="cart-detail flex1">
        <h2><a href="<?=Yii::$app->urlManager->createUrl(['goods-detail/index','product_id'=>$item['product_id']]);?>"><?= StringHelper::subtext($item['goods_name'], 18);?></a></h2>
        <!-- 产品规格 -->
        <div class="cart-spec">
         <?php if(empty($item['spec_desc'])):?>
            <i>&nbsp;</i>
          <?php else:foreach ($item['spec_desc'] as $specval):?>
            <i><?=$specval['name'];?>:<?=$specval['value'];?></i>
           <?php endforeach;endif;?>
        </div>
        <!-- 单价 -->
          <div class="cart-price">单价:
			<i><?php if ($item['price_type'] == 0):?>￥<?=$item['price'];?><?php else:?><?=$item['price'];?>试豆<?php endif;?></i> x<span class="cart-sum-amount"><?=$item['number']?></span></div>
         <!-- 类型 -->
         <div class="cart-tags"><i><?=$item['type_name'];?></i><?php if($item['free_post'] == 1):?><i>免邮</i><?php endif;?></div>
        <!-- 小计 -->
		<div class="cart-sum">小计:
         <?php if ($item['price_type'] == 0):?>
         <i>￥<?=$item['totoal_price'];?></i>
         <?php else:?>
         <i><?=$item['totoal_price'];?>试豆</i>
         <?php endif;?>
		 
		 <?php if($item['status']):?>
		 <span class="cart-edit">编辑</span>
		 <?php else:?>
		 <span class="cart-dis-del">删除</span>
		 <?php endif;?>
		 </div>
        <!-- 编辑 -->
        <div class="cart-edit-panel">
              <div class="cart-spec">
               <?php if(empty($item['spec_desc'])):?>
                 <i>&nbsp;</i>
              <?php else:foreach ($item['spec_desc'] as $specval):?>
                 <i><?=$specval['name'];?>:<?=$specval['value'];?></i>
               <?php endforeach;endif;?>
              </div>
              <div class="cart-price">单价:
				<i><?php if ($item['price_type'] == 0):?>￥<?=$item['price'];?><?php else:?><?=$item['price'];?>试豆<?php endif;?></i> x<span class="cart-sum-amount"><?=$item['number']?></span></div>
              <div class="cart-amount"><i class="amount-reduce">-</i>
                <input type="tel" class="amount-input" value="<?=$item['number']?>" size="<?=$item['size']?>">
                <i class="amount-add">+</i></div>
              <div class="cart-btns box">
                  <i class="cart-del flex1">删除</i>
                  <i class="cart-comp flex1">完成</i>
              </div>
             <div class="cart-sum">
				<?php if ($item['price_type'] == 0):?>
				<i>￥<?=$item['totoal_price'];?></i>
				<?php else:?>
				<i><?=$item['totoal_price'];?>试豆</i>
				<?php endif;?>
			 </div>
        </div>
      </div>
	  <div class="error ellipsis"></div>
    </li>
    <?php endforeach;?>
  </ul>
</section>
<div class="cart-settle" id="cartSettle">
  <div class="select-all" id="selectAll"><span class="radio"></span><i>全选</i></div>
  <div class="cart-settle-info">
    <p class="ellipsis">合计:<i class="cart-settle-amount red" id="settleAmount">￥0.00+0试豆</i></p>
    <p class="ellipsis">优惠:<i class="cart-settle-priv" id="reduceAmount">￥-0.00</i></p>
  </div>
  <div class="cart-settle-submit ellipsis" id="settleCart">去结算(<i id="settleNumber">0</i>)</div>
</div>
<form id="cartForm" method="get" action="<?=Yii::$app->urlManager->createUrl('order');?>">
<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
<input type="hidden" name="cart_ids">
</form>
<?php endif;?>
<script src="<?= Yii::getAlias('@static')?>/wap/common/js/zepto.min.js"></script>
<script src="<?= Yii::getAlias('@static')?>/wap/common/js/fastclick.min.js"></script>
<script src="<?= Yii::getAlias('@static')?>/wap/common/js/king.wap.js"></script>
<script src="<?= Yii::getAlias('@static')?>/wap/liketry/js/cart.js"></script>
<script>
var prevPageUrl = "<?=$_SERVER["HTTP_REFERER"]?>";
var cartDelUrl = "<?=Yii::$app->urlManager->createUrl('cart/del-cart');?>";
var changeNumUrl = "<?=Yii::$app->urlManager->createUrl('cart/change-num');?>";
var settleCartUrl = "<?=Yii::$app->urlManager->createUrl('order/cart-validate');?>";
var fullcut = "<?=$fullcut;?>";
</script>
